package org.jeecg.modules.system.service.impl;

import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.jeecg.modules.system.entity.SysRole;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserRole;
import org.jeecg.modules.system.mapper.SysUserRoleMapper;
import org.jeecg.modules.system.service.ISysRoleService;
import org.jeecg.modules.system.service.ISysUserRoleService;
import org.jeecg.modules.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole> implements ISysUserRoleService {
    @Autowired
    private ISysRoleService roleService;
    /**
     * 查询所有用户对应的角色信息
     */
    @Override
    public List<SysRole> queryRoleNameOfUser(String userId){
        LambdaQueryWrapper<SysUserRole> queryUDep = new LambdaQueryWrapper<SysUserRole>();
        queryUDep.eq(SysUserRole::getUserId, userId);
        List<SysUserRole> uList = this.list(queryUDep);
        List<String> roleIdList = new ArrayList<>();
        if(uList != null && uList.size() > 0) {
            for (SysUserRole uUR : uList) {
                roleIdList.add(uUR.getRoleId());
            }
            List<SysRole> userList = (List<SysRole>) roleService.listByIds(roleIdList);
            return userList;
        }
        return null;

    }
}
